<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f2f5;
            margin: 0;
        }
        .login-container {
            max-width: 700px;
            max-height: 420px;
            width: 100%;
            height: 100%;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            box-sizing: border-box;
            border-radius: 10px;
        }
        .login-container h2 {
            text-align: center;
            margin-bottom: 20px;
        }
        .form-group {
            margin-left: 10%;
            width: 80%;
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
        }
        .form-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            box-sizing: border-box;
        }
        .form-group .error {
            color: red;
            font-size: 12px;
            display: none;
        }
        .button-group {
            display: flex;
            justify-content: space-between;
        }
        .button-group button {
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        .button-group .login-btn {
            margin-right: 18%;
            width: 30%;
            background-color: #007bff;
            color: #fff;
        }
        .button-group .back-btn {
            margin-left: 18%;
            width: 30%;
            background-color: #6c757d;
            color: #fff;
        }
    </style>
    <script>
        function validateInput(input, errorElementId, minLength, errorMessage) {
            var value = input.value.trim();
            var errorElement = document.getElementById(errorElementId);
            if (value === "" || value.length < minLength) {
                errorElement.style.display = "block";
                errorElement.textContent = errorMessage;
                return false;
            } else {
                errorElement.style.display = "none";
                return true;
            }
        }

        function validateForm() {
            var isValidUsername = validateInput(document.getElementById('username'), 'usernameError', 4, '用户名不能为空且长度不能少于5个字符');
            var isValidPassword = validateInput(document.getElementById('password'), 'passwordError', 4, '密码不能为空且长度不能少于8个字符');
            return isValidUsername && isValidPassword;
        }
    </script>
</head>
<body style="background-image: url('images/江景.png'); background-repeat: no-repeat; background-size: cover; background-position: center;">
<div class="login-container">
    <h2>管理员登录</h2>
    <form action="<%= request.getContextPath() %>/login" method="post" onsubmit="return validateForm();">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" id="username" name="username" onblur="validateInput(this, 'usernameError', 4, '用户名不能为空且长度不能少于5个字符')">
            <div id="usernameError" class="error">用户名不能为空且长度不能少于5个字符</div>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" name="password" onblur="validateInput(this, 'passwordError', 4, '密码不能为空且长度不能少于8个字符')">
            <div id="passwordError" class="error">密码不能为空且长度不能少于8个字符</div>
        </div>
        <div class="button-group">
            <button type="button" class="back-btn" ><a href="login.jsp" style="text-decoration:none;color:white">返回用户登录</a></button>
            <button type="submit" class="login-btn">登录</button>
        </div>

    </form>
</div>
</body>
</html>
